<%@page contentType="text/html;charset=UTF-8"%>
<%@page import="java.util.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<title>SISTER BROTHER 聊天室</title>
<script type="text/javascript" src="/js/jquery.js"></script>
<script language="javascript" type="text/javascript">
	function sendMsg() {
		var ajax_params = {
			senderName : "sender",//物料名
			content : $("#msg").val()
		};
		$.ajax({
			url : "/Chat/save.do",
			type : "post",
			dataType : "text",
			data : ajax_params,
			timeout : 5000,
			error : function() {
			},
			success : function(data) {
				if (data == "success") {
					$("#msg").val('');
				}
			}
		});
	}
	var currentId=0;
	function getMsg() {

		$.ajax({
					url : "/Chat/getMsg.do?currentId=" + currentId,
					type : "post",
					dataType : "json",
					timeout : 5000,
					error : function() {
					},
					success : function(data) {
						for ( var i = 0; i < data.length; i++) {
							var str = '<span class="tm"> ['
									+ data[i].sendTime
									+ '] </span><a href="javascript:parent.cs('
									+ data[i].receiverName
									+ ')" target="form"'
									+ 'title="永恒一月一" class="girl">※永恒一月一</a>对<a 	href="javascript:parent.cs('
									+ data[i].reiceiverName + ');" target="form">'
									+ data[i].receiverName
									+ '</a>说：<font'+ 'color="black"> '
									+ data[i].content + '</font><br> ';
							$("#personaldiv").html(
									$("#personaldiv").html() + str);
							$("#personaldiv").scrollTop(1000000);
							if(currentId<data[i].id){
								currentId=data[i].id;
							}
						}
					}
				});
	}
	function run() {
		getMsg();
		interval = setInterval("getMsg()", 500);
	}
	run();
</script>
<style type="text/css">
body {
	font-family: "宋体";
	font-size: 10.5pt;
	background-color: #DAA520;
	/*background-image:/images/01.jpg;*/
}

.all {
	width: 1250px;
	height: 580px;
	background-color: #fff;
	margin: 35px auto;
}

.userlist {
	
}
</style>
</head>
<body>
	<table class="all">
		<tr style="width: 100%; height: 100%;">
			<td style="width: 80%; height: 100%; background-color: #FFDEAD;">
				<table style="width: 100%; height: 100%;">
					<tr style="height: 41%;">
						<td style="background-color: #8FBC8F; border: 3 solid #012345;">
							<div id="publicdiv"
								style="width: 100%; height: 100%; word-wrap: break-word; overflow-y: auto; overflow-x: hidden; float: left;">

								<span class="tm"> [20:37:05] </span><a
									href="javascript:parent.cs('永恒一月一')" target="form"
									title="永恒一月一" class="girl">※永恒一月一</a>对<a
									href="javascript:parent.cs('所有人');" target="form">所有人</a>说：<font
									color="black">1</font><br> <font color="black">1</font><br>
								<font color="black">1</font><br> <font color="black">1</font><br>
								<font color="black">1</font><br>
							</div>
						</td>
					</tr>
					<tr style="height: 41%;">
						<td style="background-color: #00FF7F;border: 3 solid #012345;">
							<div id="personaldiv"
								style="width: 100%; height: 100%; word-wrap: break-word; overflow-y: auto; overflow-x: hidden; float: left;">

								<font color="black">1</font><br> <font color="black">1</font><br>


							</div>
						</td>
					</tr>
					<tr style="height: 18%;">
						<td style="background-color: #F08080;border: 3 solid #012345;"><input name="msg"
							id="msg" size="47" maxlength="120" onkeydown="if(event.keyCode==13) sendMsg();"><input type="button"
							value="&lt;" name="cP" title="上一句话" class="btnStyle"
							onclick="gP();" ondblclick="gP();"><input type="button"
							value="&gt;" name="cN" title="下一句话" class="btnStyle"
							onclick="gN();" ondblclick="gN();"><input type="submit"
							value="发送" id="sendMsg" class="btnStyle"> <input
							type="button" value="获取" id="getMsg" class="btnStyle"></td>
					</tr>
				</table>


			</td>
			<td class="userlist" style="width: 20%; background-color: #2E8B57;"><font
				color="blue">聊天开始了</font></td>
		</tr>
	</table>
	<script type="text/javascript">
		$("#publicdiv").scrollTop(1000000);
		$("#personaldiv").scrollTop(1000000);
		$("#sendMsg").bind('click', sendMsg);
		$("#getMsg").bind('click', getMsg);
	</script>
</body>
</html>